<template>
  <p>count: {{ count }}</p>
  <button @click="fn">btn</button>
  <p>doubleCount: {{ doubleCount }}</p>

  <hr />

  <ul>
    <li v-for="item in oddArr" :key="item">{{ item }}</li>
  </ul>
</template>

<!-- <script>
import { ref, computed } from "vue";

export default {
  setup() {
    const count = ref(10);
    const fn = () => {
      count.value++;
    };
    // 计算属性需要使用从vue里面解构的computed函数
    const doubleCount = computed(() => {
      return count.value * 2;
    });

    const arr = ref([1, 2, 3, 4, 5, 6, 7]);
    const oddArr = computed(() => {
      return arr.value.filter((item) => item % 2);
    });

    return {
      count,
      fn,
      doubleCount,
      oddArr,
    };
  },
};
</script> -->

<script setup>
import { ref, computed } from "vue";

const count = ref(10);
const fn = () => {
  count.value++;
};
// 计算属性需要使用从vue里面解构的computed函数
const doubleCount = computed(() => {
  return count.value * 2;
});

const arr = ref([1, 2, 3, 4, 5, 6, 7]);
const oddArr = computed(() => {
  return arr.value.filter((item) => item % 2);
});
</script>
